package com.wenlin.myproduction.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.bean.NewPlanEn;
import com.wenlin.myproduction.util.Checker;
import com.wenlin.myproduction.util.ToastUtils;
import com.wenlin.myproduction.util.TypeData;
import com.wenlin.myproduction.util.TypeDataNames;
import com.wenlin.myproduction.util.ValCommon;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

public class BookActivity extends BaseSwipeActivity {
    @BindView(R.id.tv)
    TextView tv;
    NewPlanEn newPlanEn;

    @Override
    public int getContentView() {
        return R.layout.activity_book;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("书本详情页");
        newPlanEn = getIntent().getParcelableExtra(ValCommon.NEW_PLAN_EN);
        if (Checker.notNull(newPlanEn)) tv.setText(newPlanEn.StudyPlanName);
    }

    public static void start(BaseActivity activity, NewPlanEn newPlanEn) {
        Intent intent = new Intent(activity, BookActivity.class);
        Bundle bundle = new Bundle();
        bundle.putParcelable(ValCommon.NEW_PLAN_EN, newPlanEn);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    @OnClick({R.id.tv_complete})
    void click(View view) {
        switch (view.getId()) {
            case R.id.tv_complete:
                EventBus.getDefault().post(new TypeData<>(TypeDataNames.finishBook, newPlanEn));
                ToastUtils.getInstance().showInfo("已完成该书本");
                finish();
                break;
            default:
        }
    }
}
